package com.beta.cust.bind.datasync;

import com.alibaba.fastjson.JSONObject;
import com.beta.cust.bind.datasync.service.IWechatWorkService;
import com.beta.cust.bind.datasync.service.wechat.SyncWechatInfo;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Profile;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;

/**
 * @Auther: pcc
 * @Date: 2024/4/15 16:41
 * @Description:
 */
@SpringBootTest(classes = WebServiceApplication.class)
@Profile("qa")
@RunWith(SpringRunner.class)
public class CustBindSyncTestUnit {

    @Resource
    private SyncWechatInfo syncWechatInfo;

    @Autowired
    private IWechatWorkService wechatWorkService;

    // 定时任务 全量同步
    @Test
    public void testWechatSync() {
        syncWechatInfo.syncWechatInfoBatch("ww69b508e55f4969f8");
    }

    //1.1 新增下游企业
    @Test
    public void testCorpJoin() {
        JSONObject jo = new JSONObject();
        jo.put("ToUserName", "ww69b508e55f4969f8");
        jo.put("FromUserName", "sys");
        jo.put("MsgType", "event");
        jo.put("Event", "change_chain");
        jo.put("ChangeType", "corp_join");
        wechatWorkService.callBackCustChange(jo, "ww69b508e55f4969f8");
    }

    //1.2 更新下游企业
    @Test
    public void testUpdateJoin() {
        JSONObject jo = new JSONObject();
        jo.put("ToUserName", "ww69b508e55f4969f8");
        jo.put("FromUserName", "sys");
        jo.put("MsgType", "event");
        jo.put("Event", "change_chain");
        jo.put("ChangeType", "update_corp");
        wechatWorkService.callBackCustChange(jo, "ww69b508e55f4969f8");
    }

    //1.3 删除下游企业
    @Test
    public void testRemoveJoin() {
        JSONObject jo = new JSONObject();
        jo.put("ToUserName", "ww69b508e55f4969f8");
        jo.put("FromUserName", "sys");
        jo.put("MsgType", "event");
        jo.put("Event", "change_chain");
        jo.put("ChangeType", "remove_corp");
        wechatWorkService.callBackCustChange(jo, "ww69b508e55f4969f8");
    }

    //2.1 总公司 新增部门
    @Test
    public void testCreateParty() {
        JSONObject jo = new JSONObject();
        jo.put("ToUserName", "ww69b508e55f4969f8");
        jo.put("ChangeType", "create_party");
        jo.put("Id", "1");
        wechatWorkService.callBackEmplChange(jo, "ww69b508e55f4969f8");
    }

    //2.2 总公司 修改部门
    @Test
    public void testUpdateParty() {
        JSONObject jo = new JSONObject();
        jo.put("ToUserName", "ww69b508e55f4969f8");
        jo.put("ChangeType", "update_party");
        jo.put("Id", "1");
        wechatWorkService.callBackEmplChange(jo, "ww69b508e55f4969f8");
    }

    //2.3 总公司 删除部门
    @Test
    public void testDeleteParty() {
        JSONObject jo = new JSONObject();
        jo.put("ToUserName", "ww69b508e55f4969f8");
        jo.put("ChangeType", "delete_party");
        jo.put("Id", "1");
        wechatWorkService.callBackEmplChange(jo, "ww69b508e55f4969f8");
    }

    //2.4 子公司 新增部门
    @Test
    public void testCorpCreateParty() {
        JSONObject jo = new JSONObject();
        jo.put("ToUserName", "wpWT9DDQAABIC434dxU8a05Z3al-Rvng");
        jo.put("ChangeType", "create_party");
        jo.put("Id", "1");
        wechatWorkService.callBackEmplChange(jo, "ww69b508e55f4969f8");
    }

    //2.5 子公司 修改部门
    @Test
    public void testCorpUpdateParty() {
        JSONObject jo = new JSONObject();
        jo.put("ToUserName", "wpWT9DDQAABIC434dxU8a05Z3al-Rvng");
        jo.put("ChangeType", "update_party");
        jo.put("Id", "1");
        wechatWorkService.callBackEmplChange(jo, "ww69b508e55f4969f8");
    }

    //2.6 子公司 删除部门
    @Test
    public void testCorpDeleteParty() {
        JSONObject jo = new JSONObject();
        jo.put("ToUserName", "wpWT9DDQAABIC434dxU8a05Z3al-Rvng");
        jo.put("ChangeType", "delete_party");
        jo.put("Id", "1");
        wechatWorkService.callBackEmplChange(jo, "ww69b508e55f4969f8");
    }

    //3.1 总公司 新增员工
    @Test
    public void testCreateUser() {
        JSONObject jo = new JSONObject();
        jo.put("ToUserName", "ww69b508e55f4969f8");
        jo.put("ChangeType", "create_user");
        jo.put("UserID", "WangJiang");
        wechatWorkService.callBackEmplChange(jo, "ww69b508e55f4969f8");
    }

    //3.2 总公司 修改员工
    @Test
    public void testUpdateUser() {
        JSONObject jo = new JSONObject();
        jo.put("ToUserName", "ww69b508e55f4969f8");
        jo.put("ChangeType", "update_user");
        jo.put("UserID", "WangJiang");
        wechatWorkService.callBackEmplChange(jo, "ww69b508e55f4969f8");
    }

    //3.3 总公司 删除员工
    @Test
    public void testDeleteUser() {
        JSONObject jo = new JSONObject();
        jo.put("ToUserName", "ww69b508e55f4969f8");
        jo.put("ChangeType", "delete_user");
        jo.put("UserID", "WangJiang");
        wechatWorkService.callBackEmplChange(jo, "ww69b508e55f4969f8");
    }

    //3.4 子公司 新增员工
    @Test
    public void testCorpCreateUser() {
        JSONObject jo = new JSONObject();
        jo.put("ToUserName", "wpWT9DDQAABIC434dxU8a05Z3al-Rvng");
        jo.put("ChangeType", "create_user");
        jo.put("UserID", "woWT9DDQAAByz3peIPnghCjkTkjK4vJQ");
        wechatWorkService.callBackEmplChange(jo, "ww69b508e55f4969f8");
    }

    //3.5 子公司 修改员工
    @Test
    public void testCorpUpdateUser() {
        JSONObject jo = new JSONObject();
        jo.put("ToUserName", "wpWT9DDQAABIC434dxU8a05Z3al-Rvng");
        jo.put("ChangeType", "update_user");
        jo.put("UserID", "woWT9DDQAAByz3peIPnghCjkTkjK4vJQ");
        wechatWorkService.callBackEmplChange(jo, "ww69b508e55f4969f8");
    }

    //3.6 子公司 删除员工
    @Test
    public void testCorpDeleteUser() {
        JSONObject jo = new JSONObject();
        jo.put("ToUserName", "wpWT9DDQAABIC434dxU8a05Z3al-Rvng");
        jo.put("ChangeType", "delete_user");
        jo.put("UserID", "woWT9DDQAAByz3peIPnghCjkTkjK4vJQ");
        wechatWorkService.callBackEmplChange(jo, "ww69b508e55f4969f8");
    }

    //4.1 总公司 新增客户
    @Test
    public void testAddExternal() {
        JSONObject jo = new JSONObject();
        jo.put("ToUserName", "ww69b508e55f4969f8");
        jo.put("ChangeType", "add_external_contact");
        jo.put("UserID", "aprill");
        jo.put("ExternalUserID", "woWT9DDQAAKs0I8fS2fWlKrDciyZpecw");
        wechatWorkService.callBackCustChange(jo, "ww69b508e55f4969f8");
    }

    //4.2 总公司 删除客户
    @Test
    public void testUpdateExternal() {
        JSONObject jo = new JSONObject();
        jo.put("ToUserName", "ww69b508e55f4969f8");
        jo.put("ChangeType", "del_external_contact");
        jo.put("UserID", "aprill");
        jo.put("ExternalUserID", "woWT9DDQAAKs0I8fS2fWlKrDciyZpecw");
        wechatWorkService.callBackCustChange(jo, "ww69b508e55f4969f8");
    }

    //4.3 子公司 新增客户
    @Test
    public void testCorpAddExternal() {
        JSONObject jo = new JSONObject();
        jo.put("ToUserName", "wpWT9DDQAABIC434dxU8a05Z3al-Rvng");
        jo.put("ChangeType", "add_external_contact");
        jo.put("UserID", "woWT9DDQAAdfSQHKyX7Cqg97a7zX1Gaw");
        jo.put("ExternalUserID", "wmWT9DDQAAWZRBnEHIfCqU3QzlAz3RdA");
        wechatWorkService.callBackCustChange(jo, "ww69b508e55f4969f8");
    }


    //4.4 子公司 删除客户
    @Test
    public void testCorpUpdateExternal() {
        JSONObject jo = new JSONObject();
        jo.put("ToUserName", "wpWT9DDQAABIC434dxU8a05Z3al-Rvng");
        jo.put("ChangeType", "del_external_contact");
        jo.put("UserID", "woWT9DDQAAdfSQHKyX7Cqg97a7zX1Gaw");
        jo.put("ExternalUserID", "wmWT9DDQAAWZRBnEHIfCqU3QzlAz3RdA");
        wechatWorkService.callBackCustChange(jo, "ww69b508e55f4969f8");
    }
}
